<template>
  <div class="order">
    <!-- 面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片 -->
    <el-card>
      <!-- 搜索区域 -->
      <el-row>
        <el-col :span="8">
          <el-input placeholder="请输入内容">
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 表格数据区域 -->
      <el-table :data="orderList" border stripe>
        <el-table-column type="index" width="50px"></el-table-column>
        <el-table-column label="订单编号" prop="order_number"></el-table-column>
        <el-table-column
          label="订单价格"
          prop="order_price"
          width="140px"
        ></el-table-column>
        <el-table-column label="是否付款" prop="pay_status" width="140px">
          <template slot-scope="scoped">
            <el-tag type="success" v-if="scoped.row.pay_status == '1'"
              >已付款</el-tag
            >
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          label="是否发货"
          prop="is_send"
          width="140px"
        ></el-table-column>
        <el-table-column label="下单时间" prop="create_time" width="200px">
          <template slot-scope="scoped">{{
            scoped.row.create_time | formDate
          }}</template>
        </el-table-column>
        <el-table-column label="操作" width="200px">
          <template>
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="mini"
              title="修改订单地址"
            ></el-button>
            <el-button
              type="success"
              icon="el-icon-location"
              size="mini"
              title="物流信息"
              @click="showWLDialog"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </el-card>
    <!-- 展示物流信息对话框 -->
    <el-dialog title="查看物流进度" :visible.sync="dialogVisible" width="50%">
      <el-steps direction="vertical" :active="0">
        <el-step
          v-for="(item, index) in wlInfo"
          :key="index"
          :title="item.time"
          :description="item.context"
        ></el-step>
      </el-steps>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 查询参数对象
      queryInfo: {
        query: "",
        pagenum: 1,
        pagesize: 10
      },
      // 总条数
      total: 0,
      // 订单列表
      orderList: [],
      // 物流对话框
      dialogVisible: false,
      // 物流进度
      wlInfo: []
    };
  },
  methods: {
    // 获取订单列表
    async getOrderList() {
      const { data: res } = await this.$http.get("orders", {
        params: this.queryInfo
      });
      if (res.meta.status !== 200)
        return this.$message.error("获取订单列表失败");
      // console.log(res);
      // 总条数
      this.total = res.data.total;
      // 数据列表
      this.orderList = res.data.goods;
    },
    // 每当pagesize变化 会触发这个函数
    handleSizeChange(newSize) {
      this.queryInfo.pagesize = newSize;
      this.getOrderList();
    },
    // 每当页码值发生变化会触发这个函数
    handleCurrentChange(num) {
      this.queryInfo.pagenum = num;
      this.getOrderList();
    },
    // 展示物流对话框
    async showWLDialog() {
      // 弹框打开
      this.dialogVisible = true;
      const { data: res } = await this.$http.get("/kuaidi/1106975712662");
      if (res.meta.status !== 200)
        return this.$message.error("查询物流进度失败");
      // 把数据给物流列表
      this.wlInfo = res.data;
    }
  },
  created() {
    this.getOrderList();
  }
};
</script>

<style>
.el-table,
.el-card,
.el-pagination {
  margin-top: 15px;
}
</style>
